import { defineStore } from "pinia";
import { store } from "/@/store";
import { any, string } from "vue-types";

export const useRuleStore = defineStore({
  id: "rules",
  state: () => ({
    // 校验规则
    rules: any,
    typename: string,
    title: string,
    value: any,
    pk: string
  }),
  actions: {
    // 获取异步路由菜单
    setRules(rules) {
      this.rules = rules;
    },
    setTypeName(typename: string) {
      this.typename = typename;
    },
    setTitle(title) {
      this.title = title;
    },
    setPk(pk) {
      this.pk = pk;
    },
    setValue(val) {
      this.value = val;
    },
    // 清空缓存页面
    clearAll() {
      this.rules = [];
      this.typename = "";
      this.title = "";
      this.pk = "";
      this.value = {};
    }
  }
});

export function useRuleStoreHook() {
  return useRuleStore(store);
}
